/* Copyright (c) 2006, Jan Flora <janflora@diku.dk>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 *  - Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *  - Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *  - Neither the name of the University of Copenhagen nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
 * SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
  @author Jan Flora <janflora@diku.dk>
*/

#include <time.h>
#include "mac.h"

configuration Ieee802154MacC
{
	provides
	{
		interface StdControl;

		// interfaces for handling 802.15.4 messaging
		// MCPS
		interface IeeeIndication<Mcps_DataIndication> as McpsIndicationData;
		interface IeeeRequestConfirm<Mcps_DataRequestConfirm> as McpsRequestConfirmData;
		interface IeeeRequestConfirm<Mcps_PurgeRequestConfirm> as McpsRequestConfirmPurge;
		// MLME
		interface IeeeRequestConfirm<Mlme_AssociateRequestConfirm> as MlmeRequestConfirmAssociate;
		interface IeeeIndication<Mlme_DisassociateIndication> as MlmeIndicationDisassociate;
		interface IeeeRequestConfirm<Mlme_DisassociateRequestConfirm> as MlmeRequestConfirmDisassociate;						
		interface IeeeSyncRequestConfirm<Mlme_GetRequestConfirm> as MlmeRequestConfirmGet;
		interface IeeeRequestConfirm<Mlme_PollRequestConfirm> as MlmeRequestConfirmPoll;
		interface IeeeRequestConfirm<Mlme_ResetRequestConfirm> as MlmeRequestConfirmReset;
		interface IeeeRequestConfirm<Mlme_RxEnableRequestConfirm> as MlmeRequestConfirmRxEnable;
		interface IeeeRequestConfirm<Mlme_ScanRequestConfirm> as MlmeRequestConfirmScan;
		interface IeeeSyncRequestConfirm<Mlme_SetRequestConfirm> as MlmeRequestConfirmSet;
		
		#ifdef COORDINATOR_SUPPORT
			interface IeeeIndicationResponse<Mlme_AssociateIndicationResponse> as MlmeIndicationResponseAssociate;
			interface IeeeIndication<Mlme_CommStatusIndication> as MlmeIndicationCommStatus;
			interface IeeeIndicationResponse<Mlme_OrphanIndicationResponse> as MlmeIndicationResponseOrphan;
			interface IeeeRequestConfirm<Mlme_StartRequestConfirm> as MlmeRequestConfirmStart;
		#endif
		
		#ifdef BEACON_SUPPORT
			interface IeeeIndication<Mlme_BeaconNotifyIndication> as MlmeIndicationBeaconNotify;
			interface IeeeIndication<Mlme_SyncLossIndication> as MlmeIndicationSyncLoss;
			interface IeeeRequest<Mlme_SyncRequest> as MlmeRequestSync;
			#ifdef GTS_SUPPORT
				interface IeeeIndication<Mlme_GtsIndication> as MlmeIndicationGts;		
				interface IeeeRequestConfirm<Mlme_GtsRequestConfirm> as MlmeRequestConfirmGts;
			#endif
		#endif

		
		// interfaces for handling 802.15.4 primitive types		
		interface IeeeMacSdu as IeeeSdu;
		interface IeeeMacPibAttribute as IeeePibAttribute;
		interface IeeePanDescriptor;
		interface IeeeAddress;
		
		interface McpsDataIndication;
		interface McpsDataRequestConfirm;
		interface McpsPurgeRequestConfirm;

		interface MlmeAssociateRequestConfirm;
		interface MlmeDisassociateRequestConfirm;
		interface MlmeDisassociateIndication;
		interface MlmeGetRequestConfirm;
		interface MlmePollRequestConfirm;
		interface MlmeResetRequestConfirm;
		interface MlmeRxEnableRequestConfirm;
		interface MlmeScanRequestConfirm;
		interface MlmeSetRequestConfirm;
		
		#ifdef COORDINATOR_SUPPORT
			interface MlmeAssociateIndicationResponse;
			interface MlmeCommStatusIndication;
			interface MlmeOrphanIndicationResponse;
			interface MlmeStartRequestConfirm;
		#endif
		
		#ifdef BEACON_SUPPORT
			interface MlmeBeaconNotifyIndication;
			interface MlmeSyncRequest;
			interface MlmeSyncLossIndication;
			#ifdef GTS_SUPPORT
				interface MlmeGtsRequestConfirm;
				interface MlmeGtsIndication;
			#endif
		#endif
	}
	uses
	{
		interface PhyAttributes;
		interface PhyControl;
		interface PhyEnergyDetect;
		interface PhyReceive;
		interface PhyTransmit;
		interface PhyReset;
	
		// Alarms.
		interface AsyncAlarm<time_t> as ScanAlarm;
		interface AsyncAlarm<time_t> as EdAlarm;
		interface AsyncAlarm<time_t> as RxEnableAlarm;
		interface AsyncAlarm<time_t> as TimeoutAlarm1;
		interface AsyncAlarm<time_t> as TimeoutAlarm2;
		
		
		#ifdef BEACON_SUPPORT
			interface AsyncAlarm<time_t> as TrackAlarm;
			#ifdef COORDINATOR_SUPPORT
				interface AsyncAlarm<time_t> as BeaconAlarm;
				#ifdef GTS_SUPPORT
					interface AsyncAlarm<time_t> as GeneratorCfpAlarm;
				#endif
			#endif
			#ifdef GTS_SUPPORT
				interface AsyncAlarm<time_t> as CfpAlarm;
				interface AsyncAlarm<time_t> as CfpAlarm2;
				interface AsyncAlarm<time_t> as TrackerCfpAlarm;
			#endif
		#endif
	
		interface LocalTime<time_t>;
		
		// Fifo queueing support.
		interface FIFOQueue;
		
		// Buffer Management.
		interface MemoryManager as BufferMng;
		
		// Random
		interface Random<uint16_t>;
		
		// Debug
		interface Debug;
	}
}
implementation
{
	components EdM,
	           FrameRxM,
	           FrameTxM,
	           MacAddressM,
	           MacPibDatabaseM,
	           ScanM,
	           ScanServiceM,
	           AssociateM,
	           CapControlM,
	           #ifdef COORDINATOR_SUPPORT
		           BeaconGeneratorM,
		           StartM,
	           #endif
	           #ifdef BEACON_SUPPORT
		           BeaconTrackerM,
		           #ifdef GTS_SUPPORT
		       			CfpControlM,
		           #endif
	           #endif
	           CsmaM,
	           DataM,
	           GetSetM,
	           IndirectTxM,
	           OrphanHandlerM,
	           PollM,
	           PollServiceM,
	           RxEnableM,
	           SuperframeM,
	           TimingServiceM,
	           CallbackServiceM,
	           MacFrameM,
	           DummyM,
	           
	           PibAttributeM,
	           PanDescriptorM,
	           SduM,
	           AddressM,
	           
	           McpsDataIndicationM,
	           McpsDataRequestConfirmM,
	           McpsPurgeRequestConfirmM,
	           
	           #ifdef BEACON_SUPPORT
		           MlmeBeaconNotifyIndicationM,
		           MlmeSyncRequestM,
		           MlmeSyncLossIndicationM,
		           #ifdef GTS_SUPPORT
			           MlmeGtsRequestConfirmM,
			           MlmeGtsIndicationM,
		           #endif
	           #endif
	           
	           #ifdef COORDINATOR_SUPPORT
		           MlmeStartRequestConfirmM,
		           MlmeAssociateIndicationResponseM,
		           MlmeCommStatusIndicationM,
		           MlmeOrphanIndicationResponseM,
	           #endif
	           
	           MlmeAssociateRequestConfirmM,
	           MlmeDisassociateRequestConfirmM,
	           MlmeDisassociateIndicationM,
	           MlmeGetRequestConfirmM,
	           MlmePollRequestConfirmM,
	           MlmeResetRequestConfirmM,
	           MlmeRxEnableRequestConfirmM,
	           MlmeScanRequestConfirmM,
	           MlmeSetRequestConfirmM;

	StdControl = MacPibDatabaseM.StdControl;
	StdControl = FrameRxM.StdControl;
	StdControl = ScanM.StdControl;
	StdControl = CapControlM.StdControl;
	StdControl = CallbackServiceM.StdControl;


	// messaging wiring
	// MCPS
	McpsIndicationData = DataM.McpsIndicationData;
	McpsRequestConfirmData = DataM.McpsRequestConfirmData;
	McpsRequestConfirmPurge = IndirectTxM.McpsRequestConfirmPurge;
	
	McpsDataIndication = McpsDataIndicationM;
	McpsDataRequestConfirm = McpsDataRequestConfirmM;
	McpsPurgeRequestConfirm = McpsPurgeRequestConfirmM;
	
	//MLME
	#ifdef COORDINATOR_SUPPORT
		MlmeIndicationResponseAssociate = AssociateM.MlmeIndicationResponseAssociate;
		MlmeIndicationCommStatus = AssociateM.MlmeIndicationCommStatus;
		MlmeIndicationResponseOrphan = OrphanHandlerM.MlmeIndicationResponseOrphan;
		MlmeIndicationCommStatus = OrphanHandlerM.MlmeIndicationCommStatus;
		MlmeRequestConfirmStart = StartM.MlmeRequestConfirmStart;
	#endif

	#ifdef BEACON_SUPPORT
		MlmeIndicationBeaconNotify = BeaconTrackerM.MlmeIndicationBeaconNotify;
		MlmeIndicationSyncLoss = BeaconTrackerM.MlmeIndicationSyncLoss;
		MlmeRequestSync = BeaconTrackerM.MlmeRequestSync;
		#ifdef GTS_SUPPORT
			MlmeIndicationGts = CfpControlM.MlmeIndicationGts;
			MlmeRequestConfirmGts = CfpControlM.MlmeRequestConfirmGts;
		#endif
	#endif

	MlmeRequestConfirmAssociate = AssociateM.MlmeRequestConfirmAssociate;
	MlmeIndicationDisassociate = AssociateM.MlmeIndicationDisassociate;
	MlmeRequestConfirmDisassociate = AssociateM.MlmeRequestConfirmDisassociate;
	MlmeRequestConfirmGet = GetSetM.MlmeRequestConfirmGet;
	MlmeRequestConfirmSet = GetSetM.MlmeRequestConfirmSet;
	MlmeRequestConfirmReset = GetSetM.MlmeRequestConfirmReset;
	MlmeRequestConfirmPoll = PollM.MlmeRequestConfirmPoll;
	MlmeRequestConfirmRxEnable = RxEnableM.MlmeRequestConfirmRxEnable;
	MlmeRequestConfirmScan = ScanM.MlmeRequestConfirmScan;
	
	// primitive handling wiring
	IeeePibAttribute = PibAttributeM;
	IeeePanDescriptor = PanDescriptorM;
	IeeeSdu = SduM;
	IeeeAddress = AddressM;
	
	
	MlmeAssociateRequestConfirm = MlmeAssociateRequestConfirmM;
	MlmeDisassociateRequestConfirm = MlmeDisassociateRequestConfirmM;
	MlmeDisassociateIndication = MlmeDisassociateIndicationM;
	MlmeGetRequestConfirm = MlmeGetRequestConfirmM;
	MlmePollRequestConfirm = MlmePollRequestConfirmM;
	MlmeResetRequestConfirm = MlmeResetRequestConfirmM;
	MlmeRxEnableRequestConfirm = MlmeRxEnableRequestConfirmM;
	MlmeScanRequestConfirm = MlmeScanRequestConfirmM;
	MlmeSetRequestConfirm = MlmeSetRequestConfirmM;
	
	#ifdef COORDINATOR_SUPPORT
		MlmeAssociateIndicationResponse = MlmeAssociateIndicationResponseM;
		MlmeCommStatusIndication = MlmeCommStatusIndicationM;
		MlmeOrphanIndicationResponse = MlmeOrphanIndicationResponseM;
		MlmeStartRequestConfirm = MlmeStartRequestConfirmM;
	#endif
	
	#ifdef BEACON_SUPPORT
		MlmeBeaconNotifyIndication = MlmeBeaconNotifyIndicationM;
		MlmeSyncRequest = MlmeSyncRequestM;
		MlmeSyncLossIndication = MlmeSyncLossIndicationM;
		#ifdef GTS_SUPPORT
			MlmeGtsRequestConfirm = MlmeGtsRequestConfirmM;
			MlmeGtsIndication = MlmeGtsIndicationM;
		#endif
	#endif
	
	// Connect the PHY interfaces.
	EdM.PhyEnergyDetect = PhyEnergyDetect;
	FrameRxM.PhyReceive = PhyReceive;
	FrameRxM.PhyControl = PhyControl;
	FrameTxM.PhyTransmit = PhyTransmit;
	ScanServiceM.PhyAttributes = PhyAttributes;
	AssociateM.PhyAttributes = PhyAttributes;
	GetSetM.PhyReset = PhyReset;
	#ifdef BEACON_SUPPORT
		BeaconTrackerM.PhyAttributes = PhyAttributes;
	#endif
	#ifdef COORDINATOR_SUPPORT
		StartM.PhyAttributes = PhyAttributes;
	#endif
	
	// Wire the buffer manager
	McpsDataIndicationM.BufferMng = BufferMng;
	McpsDataRequestConfirmM.BufferMng = BufferMng;
	McpsPurgeRequestConfirmM.BufferMng = BufferMng;

	MlmeAssociateRequestConfirmM.BufferMng = BufferMng;
	MlmeDisassociateRequestConfirmM.BufferMng = BufferMng;
	MlmeDisassociateIndicationM.BufferMng = BufferMng;
	MlmeGetRequestConfirmM.BufferMng = BufferMng;
	MlmePollRequestConfirmM.BufferMng = BufferMng;
	MlmeResetRequestConfirmM.BufferMng = BufferMng;
	MlmeRxEnableRequestConfirmM.BufferMng = BufferMng;
	MlmeScanRequestConfirmM.BufferMng = BufferMng;
	MlmeSetRequestConfirmM.BufferMng = BufferMng;
	
	#ifdef COORDINATOR_SUPPORT
		BeaconGeneratorM.BufferMng = BufferMng;
		MlmeStartRequestConfirmM.BufferMng = BufferMng;
		MlmeOrphanIndicationResponseM.BufferMng = BufferMng;
		MlmeCommStatusIndicationM.BufferMng = BufferMng;
		OrphanHandlerM.BufferMng = BufferMng;
		StartM.BufferMng = BufferMng;
		IndirectTxM.BufferMng = BufferMng;
	#endif
	
	#ifdef BEACON_SUPPORT
		MlmeBeaconNotifyIndicationM.BufferMng = BufferMng;
		MlmeSyncRequestM.BufferMng = BufferMng;
		MlmeSyncLossIndicationM.BufferMng = BufferMng;
		BeaconTrackerM.BufferMng = BufferMng;
		#ifdef GTS_SUPPORT
			MlmeGtsRequestConfirmM.BufferMng = BufferMng;
			MlmeGtsIndicationM.BufferMng = BufferMng;
			CfpControlM.BufferMng = BufferMng;
		#endif
	#endif
	
	PibAttributeM.BufferMng = BufferMng;
	SduM.BufferMng = BufferMng;
	AddressM.BufferMng = BufferMng;
	ScanM.BufferMng = BufferMng;
	FrameRxM.BufferMng = BufferMng;
	AssociateM.BufferMng = BufferMng;
	DataM.BufferMng = BufferMng;
	
	// Wire fifo queue interface
	CallbackServiceM.Queue = FIFOQueue;
	
	// Wire the reset function.
	GetSetM.Reset -> AssociateM.Reset;
	GetSetM.Reset -> CapControlM.Reset;
	GetSetM.Reset -> FrameRxM.Reset;
	//GetSetM.Reset -> FrameTxM.Reset;
	GetSetM.Reset -> PollServiceM.Reset;
	GetSetM.Reset -> ScanServiceM.Reset;
	#ifdef BEACON_SUPPORT
		GetSetM.Reset -> BeaconTrackerM.Reset;
	#endif
	
	// Wire the timers.
	EdM.Alarm = EdAlarm;
	ScanServiceM.Alarm = ScanAlarm;
	RxEnableM.RxEnableAlarm = RxEnableAlarm;
	TimingServiceM.ResponseWaitAlarm = TimeoutAlarm1;
	TimingServiceM.FrameResponseAlarm = TimeoutAlarm2;
	
	SuperframeM.LocalTime = LocalTime;
	CsmaM.LocalTime = LocalTime;
	CapControlM.LocalTime = LocalTime;
	RxEnableM.LocalTime = LocalTime;
	
	#ifdef BEACON_SUPPORT
		BeaconTrackerM.TrackAlarm = TrackAlarm;
		#ifdef GTS_SUPPORT
			CfpControlM.CfpAlarm = CfpAlarm;
			CfpControlM.RxOffAlarm = CfpAlarm2;
			CfpControlM.LocalTime = LocalTime;
			BeaconTrackerM.CfpAlarm = TrackerCfpAlarm;
		#endif
		#ifdef COORDINATOR_SUPPORT
			BeaconGeneratorM.BeaconAlarm = BeaconAlarm;
			BeaconGeneratorM.LocalTime = LocalTime;
			#ifdef GTS_SUPPORT
				BeaconGeneratorM.CfpAlarm = GeneratorCfpAlarm;
			#endif
		#endif
	#endif
	
	// Wire random number generator
	MacPibDatabaseM.Random = Random;
	CsmaM.Random = Random;
	
	// Wire the address module.
	MlmeAssociateRequestConfirmM.MacAddress -> MacAddressM.MacAddress;
	MlmeDisassociateRequestConfirmM.MacAddress -> MacAddressM.MacAddress;
	MlmePollRequestConfirmM.MacAddress -> MacAddressM.MacAddress;
	PanDescriptorM.MacAddress -> MacAddressM.MacAddress;
	McpsDataRequestConfirmM.MacAddress -> MacAddressM.MacAddress;
	McpsDataIndicationM.MacAddress -> MacAddressM.MacAddress;
	
	ScanM.MacAddress -> MacAddressM.MacAddress;
	AssociateM.MacAddress -> MacAddressM.MacAddress;
	PollServiceM.MacAddress -> MacAddressM.MacAddress;
	
	#ifdef COORDINATOR_SUPPORT
		MlmeAssociateIndicationResponseM.MacAddress -> MacAddressM.MacAddress;
		BeaconGeneratorM.MacAddress -> MacAddressM.MacAddress;
		IndirectTxM.MacAddress -> MacAddressM.MacAddress;
		OrphanHandlerM.MacAddress -> MacAddressM.MacAddress;
	#endif
	
	#ifdef BEACON_SUPPORT
		BeaconTrackerM.MacAddress -> MacAddressM.MacAddress;
		#ifdef GTS_SUPPORT
			MlmeGtsRequestConfirmM.MacAddress -> MacAddressM.MacAddress;
			CfpControlM.MacAddress -> MacAddressM.MacAddress;
		#endif
	#endif
	
	// Wire framing control.
	FrameRxM.MacFrame -> MacFrameM.MacFrame;
	MlmeAssociateRequestConfirmM.MacFrame -> MacFrameM.MacFrame;
	MacAddressM.MacFrame -> MacFrameM.MacFrame;
	ScanM.MacFrame -> MacFrameM.MacFrame;
	McpsDataIndicationM.MacFrame -> MacFrameM.MacFrame;
	ScanServiceM.MacFrame -> MacFrameM.MacFrame;
	McpsDataRequestConfirmM.MacFrame -> MacFrameM.MacFrame;
	PollServiceM.MacFrame -> MacFrameM.MacFrame;
	MlmeDisassociateRequestConfirmM.MacFrame -> MacFrameM.MacFrame;
	AssociateM.MacFrame -> MacFrameM.MacFrame;
	DataM.MacFrame -> MacFrameM.MacFrame;
	
	#ifdef COORDINATOR_SUPPORT
		MlmeAssociateIndicationResponseM.MacFrame -> MacFrameM.MacFrame;
		MlmeOrphanIndicationResponseM.MacFrame -> MacFrameM.MacFrame;
		MlmeCommStatusIndicationM.MacFrame -> MacFrameM.MacFrame;
		OrphanHandlerM.MacFrame -> MacFrameM.MacFrame;
		IndirectTxM.MacFrame -> MacFrameM.MacFrame;
		BeaconGeneratorM.MacFrame -> MacFrameM.MacFrame;
	#endif
	
	#ifdef BEACON_SUPPORT
		BeaconTrackerM.MacFrame -> MacFrameM.MacFrame;
		MlmeBeaconNotifyIndicationM.MacFrame -> MacFrameM.MacFrame;
		#ifdef GTS_SUPPORT
			CfpControlM.MacFrame -> MacFrameM.MacFrame;
			MlmeGtsRequestConfirmM.MacFrame -> MacFrameM.MacFrame;
		#endif
	#endif
	
	// Wire the application callback service.
	AssociateM.CallbackService -> CallbackServiceM.CallbackService;
	DataM.CallbackService -> CallbackServiceM.CallbackService;
	GetSetM.CallbackService -> CallbackServiceM.CallbackService;
	
	#ifdef COORDINATOR_SUPPORT
		IndirectTxM.CallbackService -> CallbackServiceM.CallbackService;
		StartM.CallbackService -> CallbackServiceM.CallbackService;
	#endif
	
	#ifdef BEACON_SUPPORT
		#ifdef GTS_SUPPORT
			CfpControlM.CallbackService -> CallbackServiceM.CallbackService;
		#endif
		BeaconTrackerM.CallbackService -> CallbackServiceM.CallbackService;
	#endif
	
	// Inter-MAC wiring
	ScanServiceM.BeaconFrame -> FrameRxM.ScanBeaconFrame;
	ScanServiceM.CoordRealignFrame -> FrameRxM.CoordRealignFrame;
	ScanServiceM.FrameRx -> FrameRxM.FrameRx;
	ScanServiceM.Ed -> EdM.Ed;
	ScanServiceM.FrameTx -> FrameTxM.FrameTx[0];
	ScanM.ScanService -> ScanServiceM.ScanService;
	GetSetM.PibDatabase -> MacPibDatabaseM.PibDatabase;
	AssociateM.AssocRespFrame -> FrameRxM.AssocRespFrame;
	AssociateM.DisassocNotFrame -> FrameRxM.DisassocNotFrame;
	AssociateM.TimingService -> TimingServiceM.TimingService[0];
	AssociateM.PollService -> PollServiceM.PollService[0];
	AssociateM.DeviceTx -> CapControlM.DeviceTx[0];
	PollServiceM.DeviceRx -> CapControlM.DeviceRx;
	PollServiceM.TimingService -> TimingServiceM.TimingService[1];
	PollServiceM.PollEvents -> FrameRxM.PollEvents;
	PollServiceM.DeviceTx -> CapControlM.DeviceTx[1];
	PollM.PollService -> PollServiceM.PollService[2];
	CapControlM.Csma -> CsmaM.Csma;
	CapControlM.Superframe -> SuperframeM.Superframe;
	CapControlM.FrameRx -> FrameRxM.FrameRx;
	CsmaM.FrameTx -> FrameTxM.FrameTx[1];
	CsmaM.Superframe -> SuperframeM.Superframe;
	DataM.DataFrame -> FrameRxM.DataFrame;
	DataM.DeviceTx -> CapControlM.DeviceTx[2];
	GetSetM.FrameRx -> FrameRxM.FrameRx;
	RxEnableM.DeviceRx -> CapControlM.DeviceRx;
	RxEnableM.Superframe -> SuperframeM.Superframe;
	MacPibDatabaseM.PibChange -> CapControlM.PibChange;
	TimingServiceM.Superframe -> SuperframeM.Superframe;
	
	#ifdef COORDINATOR_SUPPORT
		BeaconGeneratorM.Superframe -> SuperframeM.Superframe;
		BeaconGeneratorM.BeaconReqFrame -> FrameRxM.BeaconReqFrame;
		BeaconGeneratorM.CoordinatorTx -> CapControlM.CoordinatorTx[0];
		StartM.CoordinatorTx -> CapControlM.CoordinatorTx[1];
		StartM.Realignment -> OrphanHandlerM.Realignment;
		IndirectTxM.CoordinatorTx -> CapControlM.CoordinatorTx[2];
		IndirectTxM.DataReqFrame -> FrameRxM.DataReqFrame;
		AssociateM.AssocReqFrame -> FrameRxM.AssocReqFrame;
		AssociateM.IndirectTx -> IndirectTxM.IndirectTx[0];
		DataM.IndirectTx -> IndirectTxM.IndirectTx[1];
		OrphanHandlerM.CoordinatorTx -> CapControlM.CoordinatorTx[3];
		OrphanHandlerM.OrphanNotFrame -> FrameRxM.OrphanNotFrame;
		RxEnableM.CoordinatorRx -> CapControlM.CoordinatorRx;
		
		MlmeOrphanIndicationResponseM.Realignment -> OrphanHandlerM.Realignment;
	#endif
	
	#ifdef BEACON_SUPPORT
		BeaconTrackerM.FrameRx -> FrameRxM.FrameRx;
		BeaconTrackerM.BeaconFrame -> FrameRxM.BeaconFrame;
		BeaconTrackerM.Superframe -> SuperframeM.Superframe;
		BeaconTrackerM.PollService -> PollServiceM.PollService[1];
		TimingServiceM.DeviceCap -> BeaconTrackerM.DeviceCap;
		CapControlM.DeviceCap -> BeaconTrackerM.DeviceCap;
		
		#ifdef GTS_SUPPORT
			BeaconTrackerM.BeaconGtsService -> CfpControlM.BeaconGtsService;
			CfpControlM.DeviceTx -> CapControlM.DeviceTx[3];
			CfpControlM.GtsReqFrame -> FrameRxM.GtsReqFrame;
			CfpControlM.Superframe -> SuperframeM.Superframe;
			CfpControlM.FrameRx -> FrameRxM.FrameRx;
			CfpControlM.DeviceCfp -> BeaconTrackerM.DeviceCfp;
			CfpControlM.FrameTx -> FrameTxM.FrameTx[3];
			DataM.CfpTx -> CfpControlM.CfpTx;
		#endif
	
		#ifdef COORDINATOR_SUPPORT
			BeaconGeneratorM.FrameTx -> FrameTxM.FrameTx[2];
			BeaconGeneratorM.BeaconDataService -> IndirectTxM.BeaconDataService;
			StartM.BeaconGenerator -> BeaconGeneratorM.BeaconGenerator;
			CapControlM.CoordinatorCap -> BeaconGeneratorM.CoordinatorCap;
			#ifdef GTS_SUPPORT
				BeaconGeneratorM.BeaconGtsService -> CfpControlM.BeaconGtsService;
				CfpControlM.CoordinatorCfp -> BeaconGeneratorM.CoordinatorCfp;
			#endif
		#endif
	#endif
	
	// Debug wiring.
	EdM.Debug = Debug;
	FrameRxM.Debug = Debug;
	FrameTxM.Debug = Debug;
	MacAddressM.Debug = Debug;
	ScanM.Debug = Debug;
	ScanServiceM.Debug = Debug;
	SuperframeM.Debug = Debug;
	GetSetM.Debug = Debug;
	AssociateM.Debug = Debug;
	TimingServiceM.Debug = Debug;
	CapControlM.Debug = Debug;
	CsmaM.Debug = Debug;
	PollServiceM.Debug = Debug;
	MacPibDatabaseM.Debug = Debug;
	PollM.Debug = Debug;
	DataM.Debug = Debug;
	RxEnableM.Debug = Debug;
	
	MlmeAssociateRequestConfirmM.Debug = Debug;
	McpsDataRequestConfirmM.Debug = Debug;
	
	#ifdef COORDINATOR_SUPPORT
		BeaconGeneratorM.Debug = Debug;
		OrphanHandlerM.Debug = Debug;
		StartM.Debug = Debug;
		IndirectTxM.Debug = Debug;
	#endif
	
	#ifdef BEACON_SUPPORT
		BeaconTrackerM.Debug = Debug;
		#ifdef GTS_SUPPORT
			CfpControlM.Debug = Debug;
		#endif
	#endif
}
